//headers 
#include<algorithm>
#include<cassert>
#include<cstdio>
#include<deque>
#include<iostream>
#include<list>
#include<map>
#include<numeric>
#include<deque>
#include<set>
#include<string>
#include<sstream>
#include<stack>
#include<streambuf>
#include<vector>
using namespace std;

//macros
#define LET(x,a) typeof(a) x(a)
#define FOR(i,a,n) for(LET(i,a);i!=n;i++)
#define REP(i,n) FOR(i,0,n)
#define sz size()
#define pb push_back
#define ALL(x) x.begin(),x.end()
#define dbge(x) cout<<#x<<"->"<<x<<endl;
#define PRINT(x) { REP(tmp,x.sz) cout<<x[tmp]<<" "; cout<<endl; }
#define OUT(x) x<<" "
#define make_pair mp
#define LL long long 
#define VI vector<int>
#define VS vector<string>
#define VVI vector< vector<int> >

const int INF = (int) 1e8;

//code of suren

int main(){
	int N; 
	while(cin>>N){ 
		map<string,int> a; VS l; VI ini(N,0);
		REP(i,N) { string _; cin>>_; l.pb(_); a[_]=0; }
		REP(i,N) {
			string name; int tot,p; cin>>name>>tot>>p;
			REP(j,l.sz) if(l[j]==name) ini[j]=tot;
			a[name]+=tot;
			REP(j,p) { string temp; cin>>temp; a[name]-=tot/p; a[temp]+=tot/p; }
		}
		REP(i,l.sz) cout<<l[i]<<" "<< a[l[i]]-ini[i]<<endl;
		cout<<endl;
	}
	return 0;
}

